﻿#include "ReportPreviewDisplay.h"

#include <iostream>

#include "MainWindow.h"
#include "GenerateReportBase.h"
#include "FinalReportData.h"

using namespace com::sun::star;

namespace GenerateReport
{
    ReportPreviewDisplay::ReportPreviewDisplay()
    {
    }

    void ReportPreviewDisplay::actionSlot_ReportPreviewDisplay(int index)
    {
        accept(index);
    }

    void ReportPreviewDisplay::accept(int index)
    {
        auto _finalReportTotalData = FinalReportDataInstance->getFinalReportTotalData();
        auto _sigleReportInfoList = _finalReportTotalData.at(index);
        m_currentDisplayReportName =_sigleReportInfoList.at(0);
        std::string _fileFullPath = _sigleReportInfoList.at(1).toStdString();

        auto _windowData = GenerateReportBaseInstance->openFile(_fileFullPath);
        qint64 _windowHWND = _windowData.first; //窗口句柄
        qint64 _windowID = _windowData.second;  //窗口映射ID
        if (_windowHWND)
        {
            GenerateReportBaseInstance->getMainWindow()->libreOfficeProcess(GenerateReport::ReportRelatedSubWidgetType::ReportPreviewDisplaySubWidget, _windowData, m_currentDisplayReportName);
            GenerateReportBaseInstance->setDocWindowVisible(_windowID, true);
        }
        else
        {
            std::cerr << "Could not get the window HWND." << std::endl;
        }

        return ;
    }

}
